HomePrize.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. "use client";
  2. import { BannerRep, PrizeTypes } from "@/api/home";
  3. import { Card } from "@/components/Card";
  4. import NoticeBox from "@/components/NoticeBox";
  5. import { Tabs } from "antd-mobile";
  6. import clsx from "clsx";
  7. import React, { FC } from "react";
  8. import "swiper/css";
  9. import { Autoplay } from "swiper/modules";
  10. import { Swiper, SwiperSlide } from "swiper/react";
  11. import styles from "./prize.module.scss";
  12. interface Props {
  13. data: PrizeTypes[];
  14. notices?: BannerRep[];
  15. type: "list" | "card" | "notice";
  16. }
  17. const HomePrize: FC<Props> = (props) => {
  18. const { data, type, notices } = props;
  19. const noticeSwiperRef = React.useRef<any>(null);
  20. const [act, setAct] = React.useState<number>(0);
  21. const renderData = React.useMemo(() => {
  22. if (type !== "notice") return data;
  23. const result: any = [];
  24. if (!!data?.length) {
  25. let bigWin: string[] = [];
  26. data.forEach((item) => {
  27. bigWin.push(
  28. `${item.phone ? item.phone.slice(0, 1) + "*****" + item.phone.slice(-3) : ""} acabou de retirar ${item.amount} R$`
  29. );
  30. });
  31. result.push({
  32. dataType: "bigWin",
  33. data: bigWin.join("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"),
  34. });
  35. }
  36. if (!!notices?.length) {
  37. notices?.forEach((item) => {
  38. result.push({
  39. dataType: "notice",
  40. data: item.content,
  41. });
  42. });
  43. }
  44. return result;
  45. }, [data, notices, type]);
  46. const noticeEnd = (idx: number) => {
  47. if (noticeSwiperRef.current) {
  48. const toIndex = idx + 1 >= renderData.length ? 0 : idx + 1;
  49. setAct(toIndex);
  50. noticeSwiperRef.current?.slideToLoop(toIndex);
  51. }
  52. };
  53. if (!renderData?.length) return null;
  54. if (type === "notice") {
  55. return (
  56. <div
  57. className={
  58. "flex items-center overflow-hidden bg-[var(--main-background)] px-[.1rem] py-[.04rem]"
  59. }
  60. >
  61. <div
  62. className={
  63. "iconfont icon-yangshengqi mr-[0.06rem] text-[.14rem] text-[var(--textColor6)]"
  64. }
  65. ></div>
  66. {/* <NoticeBox content={renderData[0].data}></NoticeBox> */}
  67. <Swiper
  68. direction="vertical"
  69. loop
  70. slidesPerView={1}
  71. className="homeNoticeSwiper"
  72. onSwiper={(swiper) => {
  73. noticeSwiperRef.current = swiper;
  74. }}
  75. style={{ height: "24px" }}
  76. >
  77. {renderData.map((item: any, index: number) => (
  78. <SwiperSlide key={index}>
  79. <NoticeBox
  80. content={item.data}
  81. start={index === act}
  82. onEnd={() => noticeEnd(index)}
  83. ></NoticeBox>
  84. </SwiperSlide>
  85. ))}
  86. </Swiper>
  87. </div>
  88. );
  89. }
  90. return (
  91. <div className={"my-[0.0694rem] px-[.1rem] pb-[.0rem]"}>
  92. {/* <div className={"mb-[0.0347rem]"}>{t("prize")}</div> */}
  93. {type === "card" && (
  94. <>
  95. <div className="mb-[.1rem] text-[0.13rem] font-bold">
  96. Grandes Vitórias Recentes
  97. </div>
  98. <Swiper
  99. slidesPerView={5.2}
  100. spaceBetween={10}
  101. pagination={{
  102. clickable: true,
  103. }}
  104. // freeMode={true}
  105. loop
  106. autoplay={{
  107. delay: 3000,
  108. }}
  109. modules={[
  110. Autoplay,
  111. // FreeMode
  112. ]}
  113. className="mySwiper"
  114. // style={{
  115. // transitionTimingFunction: "linear !important",
  116. // transitionDuration: "3000ms",
  117. // }}
  118. >
  119. {data.map((prize, index: number) => (
  120. <SwiperSlide key={index}>
  121. <div className={"w-[100%]"} style={{ borderRadius: ".1rem" }}>
  122. <Card
  123. item={prize}
  124. className="aspect-[169/234] h-[auto_!important]"
  125. />
  126. <div className={"pb-[0.0347rem] text-[0.12rem]"}>
  127. <p className={"mt-[.05rem] text-[#b77fff]"}>
  128. {prize.phone
  129. ? prize.phone.slice(0, 3) +
  130. "*****" +
  131. prize.phone.slice(-3)
  132. : ""}
  133. </p>
  134. <p className={"text-[0.11rem] text-[#43c937]"}>
  135. R${prize.amount}
  136. </p>
  137. </div>
  138. </div>
  139. </SwiperSlide>
  140. ))}
  141. </Swiper>
  142. </>
  143. )}
  144. {type === "list" && (
  145. <div className={styles.Prize}>
  146. <div className="items flex flex-row items-center justify-between">
  147. <Tabs>
  148. <Tabs.Tab title="Recente" key="recente"></Tabs.Tab>
  149. {/* <Tabs.Tab title="Vitórias" key="Vitórias"></Tabs.Tab> */}
  150. </Tabs>
  151. {/* <div>
  152. <div className={styles.desc}>Jogando Agora</div>
  153. <div className="pl-[.1rem]">52603</div>
  154. </div> */}
  155. </div>
  156. <div className="relative mt-[.15rem] rounded-[.1rem] bg-[#1f2830] px-[.15rem]">
  157. <div className={styles.item}>
  158. <div>Jogos</div>
  159. <div>Jogador</div>
  160. {/* <div>Aposta</div> */}
  161. <div>Pagamento</div>
  162. </div>
  163. <Swiper
  164. slidesPerView={10}
  165. direction="vertical"
  166. loop
  167. autoplay={{
  168. delay: 1000,
  169. }}
  170. allowTouchMove={false}
  171. modules={[Autoplay]}
  172. height={500}
  173. style={{ height: "500px" }}
  174. >
  175. {[...(data || []), ...(data || [])].map((prize, index: number) => (
  176. <SwiperSlide key={index}>
  177. <div
  178. className={clsx(styles.item, styles.normal, {
  179. [styles.even]: index % 2 === 1,
  180. })}
  181. >
  182. <div>
  183. <span>{prize.game_name}</span>
  184. </div>
  185. <div>
  186. {prize.phone
  187. ? prize.phone.slice(0, 3) +
  188. "*****" +
  189. prize.phone.slice(-3)
  190. : ""}
  191. </div>
  192. {/* <div>Aposta</div> */}
  193. <div>R${prize.amount}</div>
  194. </div>
  195. </SwiperSlide>
  196. ))}
  197. </Swiper>
  198. <div className="absolute bottom-[0] left-[0] right-[0] top-[0] z-[2]"></div>
  199. </div>
  200. </div>
  201. )}
  202. </div>
  203. );
  204. };
  205. export default HomePrize;